package com.project.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.project.common.Page;
import com.project.dao.BaseDao;
import com.project.entity.BaseEntity;

@Transactional
@Service
public class BaseService <T extends BaseEntity> {
	
	@Autowired
	@Qualifier("baseDao")
	private BaseDao<T> dao;
	
	public Page<T> queryPage(T t) {
		return dao.queryPage(t);
	}

	public List<T> query(T t) {
		return dao.query(t);
	}

	public T queryEntity(T t) {
		return dao.queryEntity(t);
	}

	public T getById(Long id) {
		return dao.getById(id);
	}
	
	public T getById(Class<?> clazz,Long id) {
		return dao.getById(clazz,id);
	}
	
	public void save(T t){
		dao.saveOrUpdate(t);
	}
	
	public void update(T t) {
		dao.update(t);
	}
	
	public void saveOrUpdate(T t) {
		dao.saveOrUpdate(t);
	}
	
	public void delete(T t) {
		dao.delete(t);
	}
	
	public void delete(Long id) {
		dao.delete(dao.getById(id));
	}
}
